﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ahao.LeetCode._1600_1699.demo1652
{
    public class Class1652
    {
        public int[] Decrypt(int[] code, int k)
        {
            int n = code.Length;
            if (k == 0)
            {
                return new int[n];
            }
            int[] res = new int[n];
            int[] newCode = new int[n * 2];
            Array.Copy(code, 0, newCode, 0, n);
            Array.Copy(code, 0, newCode, n, n);
            code = newCode;
            int l = k > 0 ? 1 : n + k;
            int r = k > 0 ? k : n - 1;
            int w = 0;
            for (int i = l; i <= r; i++)
            {
                w += code[i];
            }
            for (int i = 0; i < n; i++)
            {
                res[i] = w;
                w -= code[l];
                w += code[r + 1];
                l++;
                r++;
            }
            return res;
        }

    }
}
